<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../js/layui/css/layui.css">
    <script src="../js/layui/layui.js"></script>
</head>
<body>
<table class="layui-hide" id="productTable" lay-filter="productFilter"></table>
</body>
<script>
    var table;
    var $;
    //var form;
    layui.use(['table','form'], function(){
        table = layui.table;
        //form=layui.form;
        $=layui.jquery;
        table.render({
            id:'productTableId'
            ,elem: '#productTable'
            ,url:'../web/queryProduct'
            ,limit:6
            ,limits:[2,4,6,8,10]
            ,page:true
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,cols: [
                [
                    {field:'id', width:'10%', title: 'ID'}
                    ,{field:'workname', width:'20%', title: '职位名称'}
                    ,{field:'workingplace', width:'10%', title: '工作地点', sort: true}
                    ,{field: 'wage', title: '期望薪资', align: 'center', sort: true,templet:function(data){
                            return  data.wage +"k"
                        }}
                    ,{field:'hangye', width:'10%', title: '职位行业'}

                    ,{field:'pingjia', title: '自我评价', width: '10%', minWidth: 100} //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
                    ,{field:'worktype', width:'10%', title: '工作性质'}
                    ,{field:'update',title:'操作',width:'30%',toolbar:'#barDemo'}
                ]
            ]
        });
        table.on('tool(productFilter)', function(obj){
            var data=obj.data;
            /*alert(data.id)*/
            if(obj.event=='edit'){
                openEditProductDialog(data.id);

            }else if(obj.event=='del'){
                delOneProduct(data.id);
            }
        })
    });
    function delOneProduct(id) {
        $.ajax({
            url:'../web/delManyProduct',
            type:'post',
            data:{ids:id},
            dataType:'json',
            success:function (data) {
                if(data){
                    table.reload("productTableId",{})
                }
            }
        })
    }
    function  openEditProductDialog(id) {
        layer.open({
            type:2,
            title:'修改商品',
            area: ['700px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: '../page/updateProduct',
            btn:['保存'],
            success: function(layero,index){
                $.ajax({
                    url:'../web/findProductInfo',
                    data:{id:id},
                    dataType:'json',
                    type:'post',
                    success:function (data) {
                        var iframeWin=window[layero.find("iframe")[0]["name"]];
                        iframeWin.initForm(data);
                    }
                })
            },
            btn1:function (index,layero) {
                var iframeWin=window[layero.find("iframe")[0]["name"]];
                iframeWin.saveProduct();
                layer.close(index);
                table.reload("productTableId",{})
            }
        })
    }
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>
</html>